package com.project.finance.version.controller;

import com.project.finance.common.po.TbVersion;
import com.project.finance.common.resultconfig.Result;
import com.project.finance.common.resultconfig.ResultGenerator;
import com.project.finance.common.vo.ResultMsg;
import com.project.finance.version.service.AppVersionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author: Brendan Li
 * @description App版本
 * @Date: 2019/12/06/14:45
 */
@RestController
@RequestMapping("/api")
public class AppVersionController {

    @Autowired
    private AppVersionService versionService;

    //根据id来查询版本信息
    @RequestMapping(value = "/app",method = RequestMethod.GET)
    public Result getAppVersion(@RequestBody int id){

        TbVersion version = versionService.getVersion(id);

        Result<TbVersion> tbVersionResult = ResultGenerator.apiSuccess(version);
        return tbVersionResult;
    }

    //查询所有app版本信息
//    @RequestMapping(value = "/apps",method = RequestMethod.GET)
//    public Result selectAll(){
//        List<TbVersion> tbVersions = versionService.selectAll();
//        return ResultGenerator.apiSuccess(tbVersions);
//    }

    //修改app版本信息
    @RequestMapping(value = "/app",method = RequestMethod.PUT)
    public Result update(@RequestBody TbVersion tbVersion){
        int update = versionService.update(tbVersion);
        return ResultGenerator.apiSuccess(update);
    }
    //分页
    @RequestMapping(value = "/apps",method = RequestMethod.GET)
    public ResultMsg listVersionByPageCondition(@RequestParam("pageSize")int pageSize,
                                                @RequestParam("pageNum")int pageNum){
        ResultMsg resultMsg = versionService.listVersionByPage(pageSize, pageNum);
        resultMsg.setCode(0);
        return resultMsg;
    }

}
